<?php
/* this could be done in an iframe with a meta refresh tag and a transition tag.
the ideal aspect of that would be the new ads each time
*/

	$page = 1;
	if (isset($_REQUEST['page']))
		$page = $_REQUEST['page'];
	
	if ($page<1)
		$page = 1;

	$timelinetype = 'home_timeline';
	if (isset($_REQUEST['tlt']))
		$timelinetype = $_REQUEST['tlt'];


	$formtemplate = "Time Management";
	if (isset($_REQUEST['formtemplate']))
		$formtemplate = $_REQUEST['formtemplate'];

	include_once("dateformat.php");
//this is where the form is created.

	if (substr($formtemplate, 0, 3) == "usr")
	{
		include_once($formtemplate.".php");
	}
	else
	{
		include_once("forms/".$formtemplate.".php");
	}

	include_once("_post.php");	
?>
<form action="prepost.php" action="post">
<table width="100%" id="rowOn">
<tr>
<td colspan="2">
<h2><?php echo $formname; ?></h2>
<div>Description:<br /> <?php /*<img src="<?php echo $formavatar; ?>" width="24" height="24" />*/ ?><?php echo $formdescription; ?></div>
<br />
<div>Created By: <br /><a href="<?php echo $formauthorurl; ?>"><?php echo $formauthor; ?></a></div>
<br />
</td>
</tr>
<tr>
<?php


	$counter = 1;

	$formlength = 0;

	foreach($formentry as $formitem)
	{
?>
		<td><?php echo $formitem[1]; ?></td>
		<td>
<?php
		if ($formitem[0]==1) //textsmall
		{
?>
			<input type="text" maxlength="10" name="textsmall<?php echo $counter; ?>" value="" />
<?php
			$formlength+=10;
		}
		else if ($formitem[0] == 2) //textbig
		{
?>
			<textarea maxlength="25" name="textbig<?php echo $counter; ?>"></textarea>
<?php
			$formlength+=25;
		}
		else if ($formitem[0] == 3) //updown
		{
?>
			<input type="text" maxlength="3" name="updown<?php echo $counter; ?>" value="" />
<?php
			$formlength+=3;
		}
		else if ($formitem[0] == 4) //colorpicker
		{
?>
			<input type="text" maxlength="3" name="colorpicker<?php echo $counter; ?>" value="" />
<?php
			$formlength+=3;
		}
		else if ($formitem[0] == 5) //select
		{
?>
			<select name="select<?php echo $counter; ?>">
<?php
			$optioncounter=0;
			foreach ($formitem[2] as $formoption)
			{
?>
				<option value="<?php echo $optioncounter; ?>"><?php echo $formoption; ?></option>
<?php
				$optioncounter++;
			}
?>
			</select>
<?php
			$formlength+=3;
		}
		$counter++;
?>
	</td>
	</tr>
<?php
	}
?>
<tr>
				<td align="center" colspan="2">
<?php

if (empty($_SESSION['access_token']) || empty($_SESSION['access_token']['oauth_token']) || empty($_SESSION['access_token']['oauth_token_secret']))
{
?>
<a href="./toath/redirect.php"><img src="./toath/images/lighter.png" alt="Sign in with Twitter" border="0" /></a>
<?php
}
else
{

?>

				<input type="submit" value="update" />
<?php
}
?>
				</td>
				</tr>
</table>
</form>
<?php
	$access_token = $_SESSION['access_token'];

/* Create a TwitterOauth object with consumer/user tokens. */
	$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);

	$jsonDecode = $connection->get('statuses/'.$timelinetype, array('page' => $page));

?>
<span id="timelinetitle"><?php echo $access_token['screen_name']; ?></span><?php /*&nbsp;&nbsp;<span id="timelinecount"><?php echo count($jsonDecode); ?> tweet results</span>*/ ?>
<hr id="simplehr" />
<table id="timelinetable" cellspacing="0" cellpadding="5">
<?php
	$prunecount = 0;
	$nonformentries = 0;
	foreach ($jsonDecode as $timelineEntry)
	{
		@session_start();
		$access_token = $_SESSION['access_token'];
		$topdir = "/home/boostpo1/public_html/chirplace.com/usr/".$access_token['user_id']."/prune/".$timelineEntry->user->id.".pne";
		$fh = @fopen($topdir, 'r');
		$pruneamount = @fread($fh, filesize($topdir));
		@fclose($fh);
	
		$threshold = rand(1, 100);

		if ($pruneamount>$threshold)
		{
			$prunecount++;
		}
		else
		{
			$timelineEntry->text = formatTweet($timelineEntry->text);
			if (strcmp(trim($timelineEntry->text), "--nopost")!=0)
			{

				if ($formlength == strlen($timelineEntry->text))
				{
	?>
	
	<tr>
		<td valign="top">
			<a class="dock-item2" href="http://www.twitter.com/<?php echo $timelineEntry->user->screen_name; ?>"><img src="<?php echo $timelineEntry->user->profile_image_url; ?>" alt="(~.~)" title="<?php echo $timelineEntry->user->description;?>" width="48" height="48" border="0" /></a><form action="index.php" method="GET"><input type="hidden" name="start" value="prune" /><input type="hidden" name="tuser" value="<?php echo $timelineEntry->user->id; ?>" /><input type="hidden" name="tusername" value="<?php echo $timelineEntry->user->screen_name; ?>" /><input type="image" src="images/pruneicon.jpg" alt="Prune <?php echo $timelineEntry->user->screen_name; ?>" title = "Prune <?php echo $timelineEntry->user->screen_name; ?>" value="p" /></form>
		</td>
		<td valign="top">
	<?php
				// 1. Determine how many characters this form entry must be. if tweet is correct length, proceed to parse.
				
					//we have a match. Deserialize.
					$startind = 0;
					foreach($formentry as $formitem)
					{
						if ($formitem[0]==1) //textsmall
						{
							$val = substr($timelineEntry->text, $startind, 10);
							echo "<strong>".$formitem[1]."</strong>: ".str_replace("_", "", $val)."<br />";
							$startind+=10;
						}
						else if ($formitem[0]==2) //textbig
						{
							$val = substr($timelineEntry->text, $startind, 25);
							echo "<strong>".$formitem[1]."</strong>: ".str_replace("_", "", $val)."<br />";
							$startind+=25;
						}
						else if ($formitem[0] == 3) //updown
						{
							$val = substr($timelineEntry->text, $startind, 3);
							echo "<strong>".$formitem[1]."</strong>: ".str_replace("_", "", $val)."<br />";
							$startind+=3;
						}
			
						else if ($formitem[0] == 4) //colorpicker
						{
							$val = substr($timelineEntry->text, $startind, 6);
							echo "<strong>".$formitem[1]."</strong>: ".str_replace("_", "", $val)."<br />";
							$startind+=6;
						}
						else if ($formitem[0] == 5) //select
						{
							$val = substr($timelineEntry->text, $startind, 3);
							
							echo "<strong>".$formitem[1]."</strong>: ".$formitem[2][(int)$val]."<br />";
							$startind+=3;
						}
					}
	?>
		<tr>
			<td colspan="2"><hr id="simplehr" /></td>
		</tr>
	<?php
				}
				else
				{
	/*
	?>
	<a href="http://www.twitter.com/<?php echo $timelineEntry->user->screen_name; ?>"><?php echo $timelineEntry->user->screen_name; ?></a> <span><?php echo ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "<a href=\"\\0\">\\0</a>", $timelineEntry->text); ?></span><div id="entrysource"><?php echo formatDate($timelineEntry->created_at); ?> from <?php echo $timelineEntry->source; ?></div>
	
	<?php
	*/
					$nonformentries++;
				}
/*
?>
</td>
	</tr>
	<tr>
		<td colspan="2"><hr id="simplehr" /></td>
	</tr>
<?php
*/
			}
		}
	}
	
?> 
	<tr>
		<td></td>
		<td>
			<div id="entrysource"><?php echo $prunecount; ?> posts were pruned from this list.</div>
			<div id="entrysource"><?php echo $nonformentries; ?> posts were not displayed due to form filtering.</div>
		</td>
	</tr>
	<tr>
		<td>
			
		</td>
		<td>
			<form action="index.php" method="GET">
			<input type="hidden" name="start" value="forms" />
			<input type="hidden" name="tlt" value="<?php echo $timelinetype; ?>" />
			<input type="hidden" name="page" value="<?php echo $page-1; ?>" />
			<input type="submit" value="newer" id="pagebutton" />
			</form>			
			<form action="index.php" method="GET">
			<input type="hidden" name="start" value="forms" />
			<input type="hidden" name="tlt" value="<?php echo $timelinetype; ?>" />
			<input type="hidden" name="page" value="<?php echo $page+1; ?>" />
			<input type="submit" value="older" id="pagebutton" />
			</form>
		</td>
	</tr>
</table>